package gestionSimpleATester;

import static org.junit.Assert.*;

import java.util.Random;
import java.util.Vector;

import junit.framework.Assert;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class AccountTest_II {

	Account a;
	
	@Before
	public void setUp() throws Exception {
		a= new Account(new Person("person"),1f,10f,100);
	}

	@After
	public void tearDown() throws Exception {
		a= null;
	}

	@Test
	public void testAccount() {
		Assert.assertNotNull(a);
		Assert.assertEquals(a.getOwner().getName(),"person");
		Assert.assertEquals(a.getBalance(), 1f);
		Assert.assertEquals(a.getOverdraft(), 10f);
		Assert.assertEquals(a.getNumber(), 100);
	}
	@Test
	public void testDeposit() throws Exception {
		/*** BUG OPERATION #12**/
		float oldValue = a.getBalance();
		float depValue = new Random().nextFloat() * 1000;
		a.deposit(depValue);
		Assert.assertEquals(a.getBalance(), oldValue+depValue);
		Vector<Operation> vH = new Vector<Operation>();
		vH=  (Vector) a.getHistory();
		for (int i = 0 ;i< a.getHistory().size();i++){
			Assert.assertEquals(vH.get(i).getOperationType()	,"Deposit");
			System.out.println();
			Assert.assertEquals(vH.get(i).getAmount(), depValue);
		}
	}

	@Test
	public void testWithdraw() {
		fail("Not yet implemented");
	}

	@Test
	public void testGetHistory() {
		fail("Not yet implemented");
	}

	@Test
	public void testSetHistory() {
		fail("Not yet implemented");
	}

	@Test
	public void testHistoryIterator() {
		fail("Not yet implemented");
	}

	@Test
	public void testAddHistory() throws Exception {
		DepositOperation dO = new DepositOperation(1000f);
		a.addHistory(dO);
		Assert.assertEquals(a.getHistory().size(), 1);
	}

	@Test
	public void testRemoveHistory() {
		fail("Not yet implemented");
	}

	@Test
	public void testIsHistoryEmpty() {
		Assert.assertTrue(a.isHistoryEmpty());
	}

	@Test
	public void testClearHistory() {
		fail("Not yet implemented");
	}

	@Test
	public void testContainsHistory() {
		fail("Not yet implemented");
	}

	@Test
	public void testContainsAllHistory() {
		fail("Not yet implemented");
	}

	@Test
	public void testHistorySize() {
		fail("Not yet implemented");
	}

	@Test
	public void testHistoryToArray() {
		try {
		a.addHistory(new DepositOperation(2000f));
		
		a.addHistory(new DepositOperation(5500f));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		Operation[] history =  a.historyToArray();
		for (int i = 0;i<history.length;i++){
			System.out.println("IIIII "+ history[i].getOperationType()+ " IIIII " + history[i].getAmount());
		}
	}

	@Test
	public void testGetOverdraft() {
		Assert.assertEquals(a.getOverdraft(), 10f);
	}

	@Test
	public void testSetOverdraft() {
		float bValue = new Random().nextFloat() * 10;
		a.setOverdraft(bValue);
		Assert.assertEquals(a.getOverdraft(),bValue);
		a.setOverdraft(-bValue);
		Assert.assertEquals(a.getOverdraft(),-bValue);
	}

	@Test
	public void testGetBalance() {
		Assert.assertEquals(a.getBalance(), 1f);
	}

	@Test
	public void testSetBalance() {
		float bValue = new Random().nextFloat() * 10;
		a.setBalance(bValue);
		Assert.assertEquals(a.getBalance(),bValue);
		a.setBalance(-bValue);
		Assert.assertEquals(a.getBalance(),-bValue);
		
	}

	@Test
	public void testGetNumber() {
		Assert.assertEquals(a.getNumber(), 100);
	}

	@Test
	public void testSetNumber() {
		a.setNumber(99);
		Assert.assertEquals(a.getNumber(), 99);
		a.setNumber(999999);
		Assert.assertEquals(a.getNumber(), 999999);
	}

	@Test
	public void testGetOwner() {
		Assert.assertEquals(a.getOwner().getName(),"person");
	}

	@Test
	public void testSetOwner() {
		Person p1 = new Person("Monik");
		a.setOwner(p1);
		Assert.assertEquals(a.getOwner().getName(), p1.getName());
		Assert.assertEquals(a.getOwner(), p1);
	}
}
